package cn.taokuaidi.wangwang.client.context;

import cn.taokuaidi.wangwang.client.constants.AppEvents;
import cn.taokuaidi.wangwang.client.data.Request;
import cn.taokuaidi.wangwang.client.dataProxy.ChartDataProxy;
import cn.taokuaidi.wangwang.client.model.ChartDO;
import cn.taokuaidi.wangwang.client.reader.ChartReader;

import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;

/**
 * @author 嘉陵江里捉鱼 email:tang7259@163.com
 *@version 1.0
 *@time Nov 3, 2008 11:10:30 AM
 */
public class ChartEventContext {

    public static ListStore<ChartDO> getStore() {
        return store;
    }

    private static ListStore<ChartDO> store;

    public static void load() {
        ChartDataProxy proxy = new ChartDataProxy(Request.getCharts());
        ListLoader loader = new BaseListLoader(proxy, new ChartReader<ModelData>()) {

            @Override
            protected void onLoadSuccess(Object loadConfig, Object data) {
                super.onLoadSuccess(loadConfig, data);
                Dispatcher.forwardEvent(AppEvents.ALL_CHART_LOADED);

            }

        };
        store = new ListStore<ChartDO>(loader);
        loader.load();
    }
}
